<?php
class UuidLog extends BaseActiveRecord
{
    
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return '{{uuid_log}}';
    }

    public function add($id)
    {
        $result = 0;
        $old_data = $this->isExist($id);
        if ($old_data) {
            return $old_data;
        }
        $new_data = New UuidLog;
        $new_data->uuid= $id;
        $new_data->ctime = time();
        if ($new_data->save()) {
            $result = $new_data->id;
        }
        return $result;
    }
    public function isExist($id)
    {
        $result = false;
        if (!empty($id)) {
            $criteria = new CDbCriteria;
            $criteria->addColumnCondition(array('uuid'=>$id));
            $criteria->addCondition('ctime>='.time()-100);
            $data = $this->find($criteria);
            if(!empty($data))
            {
                $result = true;
            }
        }
        return $result;
    }

}

?>